<template>
	<view>
		<div class="xjsy">
			<div class="czmm">
				<ul>
					<li>
						<image mode="widthFix" class="uni-img-tag" src="https://iyouhaolife-1316622368.cos.ap-chongqing.myqcloud.com/h5/static/imgs/a41.png" />
						<p>验证手机</p>
					</li>
					<li>
						<image mode="widthFix" class="uni-img-tag" src="https://iyouhaolife-1316622368.cos.ap-chongqing.myqcloud.com/h5/static/imgs/a42.png" />
						<p>设置密码</p>
					</li>
					<li>
						<image mode="widthFix" class="uni-img-tag" src="https://iyouhaolife-1316622368.cos.ap-chongqing.myqcloud.com/h5/static/imgs/a43.png" />
						<p><span>重置成功</span></p>
					</li>
				</ul>
			</div>
			<div class="mmsz">
				<ul>
					<li><span>
							<image mode="widthFix" class="uni-img-tag" src="https://iyouhaolife-1316622368.cos.ap-chongqing.myqcloud.com/h5/static/imgs/a44.png"></image>
						</span><input v-model="formData.password" type="password" class="wby2" placeholder="请设置密码" />
					</li>
					<li><span>
							<image mode="widthFix" class="uni-img-tag" src="https://iyouhaolife-1316622368.cos.ap-chongqing.myqcloud.com/h5/static/imgs/a44.png"></image>
						</span><input v-model="formData.confirmPassword" type="password" class="wby2"
							placeholder="请再次设置密码" /></li>
				</ul>
			</div>
			<button type="button" @click="submit" :class="{disabled:!pwdSuccess}" class="btn1">确定</button>
		</div>
	</view>
</template>

<script>
	import user from "@/common/user.js"
	export default {
		data() {
			return {
				formData: {
					mobile: '',
					code: '',
					password: '',
					confirmPassword: '',
				}
			}
		},
		onLoad(option) {
			this.formData.mobile = option.mobile;
			this.formData.code = option.code;
		},
		computed: {
			pwdSuccess() {
				if (!this.formData.password) {
					return false
				}
				return this.formData.password == this.formData.confirmPassword;
			}
		},
		methods: {
			submit() {

				if (!this.formData.password) {
					uni.showToast({
						icon: "error",
						title: "请输入密码"
					})
					return
				}

				if (!this.formData.confirmPassword) {
					uni.showToast({
						icon: "error",
						title: "请输入确认密码"
					})
					return
				}

				if (this.formData.password != this.formData.confirmPassword) {
					uni.showToast({
						icon: "error",
						title: "两次密码不一致"
					})
					return
				}

				user.resetPassword(this.formData, ret => {
          uni.showModal({
            showCancel:false,
            title: "重置密码成功",
            success() {
              uni.reLaunch({
                url: 'login'
              })
            }
          })

				})
			}
		}
	}
</script>

<style>

</style>
